/**
 * 
 */
package com.ultimatetech.cim.graphical;

import javax.wbem.cim.CIMClass;

import org.eclipse.draw2d.Label;
import org.eclipse.draw2d.MouseEvent;
import org.eclipse.draw2d.MouseListener;
import org.eclipse.ui.PartInitException;
import org.eclipse.ui.PlatformUI;

import com.ultimatetech.cim.views.CIMClassHierarchyView;

public class UMLCIMClassMouseListener implements MouseListener {
	/**
	 * 
	 */
	private CIMClass cimClass;

	/**
	 * @param class1
	 */
	public UMLCIMClassMouseListener(CIMClass cc) {
		cimClass = cc;
	}

	public void mousePressed(MouseEvent me) {
		
	}

	public void mouseReleased(MouseEvent me) {
		System.out.println("Mouse released");
		if(me.button == 3) {
			System.out.println("button 3 released");
			me.consume();
		} else if(me.button == 2){
			System.out.println("button 2 released");
			me.consume();
		} /*else {
			System.out.println("Mouse button released:" + me.button + 
					"; ME.BUTTON1:" + MouseEvent.BUTTON1 +
					"; ME.BUTTON2:" + MouseEvent.BUTTON2 +
					"; ME.BUTTON3:" + MouseEvent.BUTTON3 +
					"; ME.BUTTON4:" + MouseEvent.BUTTON4 +
					"; ME.BUTTON5:" + MouseEvent.BUTTON5);
		}*/
	}

	public void mouseDoubleClicked(MouseEvent me) {
		try {			
			CIMClassHierarchyView view = (CIMClassHierarchyView)
			PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().showView(
			"com.ultimatetech.cim.views.CIMClassHierarchyView");
			if(view.getCimObjectPath() == null || 
					!view.getCimObjectPath().equals(cimClass.getObjectPath())){
				view.setCimObjectPath(cimClass.getObjectPath());
			}
			Object o = me.getSource();
			if(o instanceof Label){
				((Label)o).handleMouseExited(me);
			}
			me.consume();
		} catch (PartInitException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
	}
	  
  }